% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
{\ttfamily \raggedright {
\noindent
\mbox{}\textit{\textcolor{Brown}{//n!\ mod\ p}} \\
\mbox{}\textcolor{ForestGreen}{int}\ \textbf{\textcolor{Black}{factmod}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ n\textcolor{BrickRed}{,}\ \textcolor{ForestGreen}{int}\ p\textcolor{BrickRed}{)}\ \textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \ \ \textcolor{ForestGreen}{long}\ \textcolor{ForestGreen}{long}\ res\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{1}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(}n\ \textcolor{BrickRed}{$>$}\ \textcolor{Purple}{1}\textcolor{BrickRed}{)}\ \textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ res\ \textcolor{BrickRed}{=}\ \textcolor{BrickRed}{(}res\ \textcolor{BrickRed}{*}\ \textbf{\textcolor{Black}{powmod}}\ \textcolor{BrickRed}{(}p\textcolor{BrickRed}{-}\textcolor{Purple}{1}\textcolor{BrickRed}{,}\ n\textcolor{BrickRed}{/}p\textcolor{BrickRed}{,}\ p\textcolor{BrickRed}{))}\ \textcolor{BrickRed}{\%}\ p\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{2}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{$<$=}n\textcolor{BrickRed}{\%}p\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}i\textcolor{BrickRed}{)} \\
\mbox{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ res\ \textcolor{BrickRed}{=}\ \textcolor{BrickRed}{(}res\ \textcolor{BrickRed}{*}\ i\textcolor{BrickRed}{)}\ \textcolor{BrickRed}{\%}\ p\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ n\ \textcolor{BrickRed}{/=}\ p\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \ \ \ \ \ \textbf{\textcolor{Blue}{return}}\ \textcolor{ForestGreen}{int}\ \textcolor{BrickRed}{(}res\ \textcolor{BrickRed}{\%}\ p\textcolor{BrickRed}{);} \\
\mbox{}\textcolor{Red}{\}}
}